package com.esm.sm800.database.manager;

import com.esm.sm800.activity.AppContext;
import com.esm.sm800.database.dbmodel.Warehousing;
import com.esm.sm800.database.dbmodel.Warehousing_record;
import com.esm.sm800.database.greendao.Warehousing_recordDao;

import java.util.ArrayList;

public class WarehousingrecordCenter {

    private static WarehousingrecordCenter instance = new WarehousingrecordCenter();

    public static WarehousingrecordCenter getInstance() {
        return instance;
    }

     public Warehousing_record getWarehousing_record(String position) {
        Warehousing_record Warehousing_record = null;
        try {
            Warehousing_recordDao Warehousing_recordDao = AppContext.getInstances().getDaoSession().getWarehousing_recordDao();
            ArrayList<Warehousing_record> list = new ArrayList<Warehousing_record>();
            list = (ArrayList) Warehousing_recordDao.queryBuilder()
                    .where(com.esm.sm800.database.greendao.Warehousing_recordDao.Properties.Position.eq(position))
                    .build().list();
            if (list.size() > 0) {
                Warehousing_record = list.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return Warehousing_record;
    }

    public Long saveWarehousing_record(Warehousing_record Warehousing_record) {
        if (Warehousing_record == null) {
            return 0L;
        }

        try {
            Warehousing_recordDao Warehousing_recordDao = AppContext.getInstances().getDaoSession().getWarehousing_recordDao();
            long id = Warehousing_recordDao.insertOrReplace(Warehousing_record);
            return id;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return 0L;
    }

    public ArrayList<Warehousing_record> warehousing_recordlist = null;

    public ArrayList<Warehousing_record> getWarehousing_recordlist() {
        ArrayList<Warehousing_record> list = new ArrayList<Warehousing_record>();
        try {
            Warehousing_recordDao Warehousing_recordDao = AppContext.getInstances().getDaoSession().getWarehousing_recordDao();
            list = (ArrayList) Warehousing_recordDao.queryBuilder()
                    .orderDesc(com.esm.sm800.database.greendao.Warehousing_recordDao.Properties.Update_time)
                    .build().list();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
}
